package f5transformation;

import flinkemp.Emp;
import flinkemp.EmpFun;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

public class FlatMap2 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(1);
        DataStreamSource<Emp> data = env.addSource(new EmpFun());
        data.print();
        data.flatMap((Emp emp, Collector<String> collector) -> {
            if (emp.sal >= 5000 && emp.sal < 7000) {
                collector.collect("低薪\t\t姓名:" + emp.eName + "\t薪资:" + emp.sal + "\t岗位:" + emp.job);
            }
            else if (emp.sal >= 7000 && emp.sal < 9000) {
                collector.collect("中薪\t\t姓名:" + emp.eName + "\t薪资:" + emp.sal + "\t岗位:" + emp.job);
            }
            else if (emp.sal >= 9000) {
                collector.collect("高薪\t\t姓名:" + emp.eName + "\t薪资:" + emp.sal + "\t岗位:" + emp.job);
            }
        }).returns(new TypeHint<String>() {
        }).print();
        env.execute();
    }
}
